package com.zrong.gamesdk.test.integration.thread;

import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.THttpClient;
import org.apache.thrift.transport.TTransport;

public class CommonCommentThread  implements Runnable {
	private String commentContent;
	private String targetOjbect;
	private Integer commentOrigin;
	private long userId;
	private long times;

	public CommonCommentThread(String commentContent,String targetOjbect, String commentOrigin,
			long userId, long times) {
		this.commentContent=commentContent;
		this.targetOjbect = targetOjbect;
		this.commentOrigin = Integer.valueOf(commentOrigin);;
		this.userId = userId;
		this.times = times;
	}
	private CommonCommentClient.Client createCommonCommentClient() throws Exception {
        TTransport transport = new THttpClient("http://localhost:8080/UserPartake/service/thrift/commonComment");
        TProtocol protocol = new TBinaryProtocol(transport);
        CommonCommentClient.Client client = new CommonCommentClient.Client(protocol);
        return client;
    }

	public CommonCommentThread() {

	}

	@Override
	public void run() {
		try {
			CommonCommentClient.Client client = this.createCommonCommentClient();
            for (long i = 0; i < times; i++) {
            	CommonComment commonComment = new CommonComment();
            	commonComment.setCommentContent(this.commentContent);
            	commonComment.setCommentOrigin(this.commentOrigin);
            	commonComment.setTargetObject(this.targetOjbect);
            	commonComment.setUserId(userId);
            	commonComment.setCommentType(1001);
                client.saveCommonComment(commonComment);
            }
        } catch (Exception e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
		
	}
}
